package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.article.ApAuthorControllerApi;
import com.usian.article.service.ApAuthorService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/v1/author")
@RestController
public class ApAuthorController implements ApAuthorControllerApi {

    @Autowired
    private ApAuthorService apAuthorService;

    @GetMapping("/findByUserId")
    @Override
    public ApAuthor findByUserId(Integer id) {
        return apAuthorService.findByUserId(id);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult add(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.add(apAuthor);
    }

    @GetMapping("/findByName/{name}")
    @Override
    public ApAuthor findByName(@PathVariable("name") String name) {
        ApAuthor apAuthor = apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getName, name));
        return apAuthor;
    }

    @GetMapping("/one/{id}")
    @Override
    public ApAuthor findById(@PathVariable Integer id) {
        return apAuthorService.getById(id);
    }
}
